{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Pre-Tutorial Exercises\n",
    "\n",
    "If you've arrived early for the tutorial, please feel free to attempt the following exercises to warm-up."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. Basic Python data structures\n",
    "# I have a list of dictionaries as such:\n",
    "\n",
    "names = [{'name': 'Eric',\n",
    "          'surname': 'Ma'},\n",
    "         {'name': 'Jeffrey',\n",
    "          'surname': 'Elmer'},\n",
    "         {'name': 'Mike',\n",
    "          'surname': 'Lee'},\n",
    "         {'name': 'Jennifer',\n",
    "          'surname': 'Elmer'}]\n",
    "\n",
    "# Write a function that takes in a list of dictionaries and a query surname, \n",
    "# and searches it for all individuals with a given surname.\n",
    "\n",
    "def find_persons_with_surname(persons, query_surname):\n",
    "    # Assert that the persons parameter is a list. \n",
    "    # This is a good defensive programming practice.\n",
    "    assert isinstance(persons, list)   \n",
    "    \n",
    "    results = []\n",
    "    for ______ in ______:\n",
    "        if ___________ == __________:\n",
    "            results.append(________)\n",
    "    \n",
    "    return results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Test your result below.\n",
    "results = find_persons_with_surname(names, 'Lee')\n",
    "assert len(results) == 1\n",
    "\n",
    "results = find_persons_with_surname(names, 'Elmer')\n",
    "assert len(results) == 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "colors": {
    "hover_highlight": "#DAA520",
    "navigate_num": "#000000",
    "navigate_text": "#333333",
    "running_highlight": "#FF0000",
    "selected_highlight": "#FFD700",
    "sidebar_border": "#EEEEEE",
    "wrapper_background": "#FFFFFF"
   },
   "moveMenuLeft": true,
   "nav_menu": {
    "height": "30px",
    "width": "252px"
   },
   "navigate_menu": true,
   "number_sections": true,
   "sideBar": true,
   "threshold": 4,
   "toc_cell": false,
   "toc_section_display": "block",
   "toc_window_display": false,
   "widenNotebook": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
